package com.sdry.web.controller.lz;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sdry.model.lz.DeviceModel;
import com.sdry.model.lz.HighChartsParam;
import com.sdry.model.zc.ZcEvaluateEntity;
import com.sdry.service.lz.DeviceOperateMService;
import com.sdry.utils.ResponseUtil;

/**
 * @ClassName DeviceOperateMController
 * @Description 设备运行管理
 * @Author lz
 * @Date 2019年1月9日 11:02:58
 * @Version 1.0
 */
@Controller
@RequestMapping("/operateMC")
public class DeviceOperateMController {

	@Resource
	DeviceOperateMService deviceOperateMService;
	
	public static final Integer AFFECT_ROW = 0;
	HighChartsParam highChartsParam1 = null;
	HighChartsParam highChartsParam2 = null;
	HighChartsParam highChartsParam3 = null;
	HighChartsParam highChartsParam4 = null;
	HighChartsParam highChartsParam5 = null;
	HighChartsParam highChartsParam6 = null;
	Object[] array = null;
	JSONObject jsonObject = null;
	/**
	 * 查询所有离心机的状态
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("/queryAllDeviceStatus")
	public void queryAllDeviceStatus(HttpServletResponse response) throws Exception{
		Double count1 = 0.00;
		Double count2 = 0.00;
		Double count3 = 0.00;
		Double count4 = 0.00;
		Double count5 = 0.00;
		array = new Object[5];
		jsonObject = new JSONObject();
		highChartsParam1 = new HighChartsParam();
		highChartsParam2 = new HighChartsParam();
		highChartsParam3 = new HighChartsParam();
		highChartsParam4 = new HighChartsParam();
		highChartsParam5 = new HighChartsParam();
		List<DeviceModel> deviceModelList = deviceOperateMService.queryAllDeviceStatus();
		if(deviceModelList.size() > 0){
			for (int i = 0; i < deviceModelList.size(); i++) {
				if("绑定".equals(deviceModelList.get(i).getRemark05())){
					count1 ++;
				} else if("1遍浇".equals(deviceModelList.get(i).getRemark05())){
					count2 ++;
				} else if("2遍浇".equals(deviceModelList.get(i).getRemark05())){
					count3 ++;
				} else if("3遍浇".equals(deviceModelList.get(i).getRemark05())){
					count4 ++;
				} else {
					count5 ++;
				}
			}
			highChartsParam1.setName("绑定");
			highChartsParam1.setY(count1);
			highChartsParam1.setDrilldown("绑定");
			
			highChartsParam2.setName("1遍浇");
			highChartsParam2.setY(count2);
			highChartsParam2.setDrilldown("1遍浇");
			
			highChartsParam3.setName("2遍浇");
			highChartsParam3.setY(count3);
			highChartsParam3.setDrilldown("2遍浇");
			
			highChartsParam4.setName("3遍浇");
			highChartsParam4.setY(count4);
			highChartsParam4.setDrilldown("3遍浇");
			
			highChartsParam5.setName("空闲");
			highChartsParam5.setY(count5);
			highChartsParam5.setDrilldown("空闲");
			
			array[0] = highChartsParam1;
			array[1] = highChartsParam2;
			array[2] = highChartsParam3;
			array[3] = highChartsParam4;
			array[4] = highChartsParam5;
			
			JSONArray jsonArray = JSONArray.fromObject(array);
			jsonObject.put("name", "离心机状态");
	        jsonObject.put("colorByPoint", true);
	        jsonObject.put("data", jsonArray);
			ResponseUtil.write(response, jsonObject);
		} else {
			ResponseUtil.write(response, "");
		}
	}
	
	/**
	 * 通过设备编号查询组件评价
	 * @param response
	 * @param deviceNumber
	 * @throws Exception 
	 */
	@RequestMapping("/queryEvaluateByDeviceNumber")
	public void queryEvaluateByDeviceNumber(HttpServletResponse response, String deviceNumber) throws Exception{
		ZcEvaluateEntity zcEvaluateEntity = deviceOperateMService.queryEvaluateByDeviceNumber(deviceNumber);
		jsonObject = new JSONObject();
		array = new Object[6];
		highChartsParam1 = new HighChartsParam();
		highChartsParam2 = new HighChartsParam();
		highChartsParam3 = new HighChartsParam();
		highChartsParam4 = new HighChartsParam();
		highChartsParam5 = new HighChartsParam();
		highChartsParam6 = new HighChartsParam();
		if(zcEvaluateEntity != null){
			highChartsParam1.setName("运行水温");
			highChartsParam1.setY(Double.parseDouble(zcEvaluateEntity.getYxsw()));
			highChartsParam1.setDrilldown("运行水温");
			
			highChartsParam2.setName("进水压力");
			highChartsParam2.setY(Double.parseDouble(zcEvaluateEntity.getJsyl()));
			highChartsParam2.setDrilldown("进水压力");
			
			highChartsParam3.setName("产水压力");
			highChartsParam3.setY(Double.parseDouble(zcEvaluateEntity.getJsyl()));
			highChartsParam3.setDrilldown("产水压力");
			
			highChartsParam4.setName("浓水压力");
			highChartsParam4.setY(Double.parseDouble(zcEvaluateEntity.getNsyl()));
			highChartsParam4.setDrilldown("浓水压力");
			
			highChartsParam5.setName("产水通量");
			highChartsParam5.setY(Double.parseDouble(zcEvaluateEntity.getCstl()));
			highChartsParam5.setDrilldown("产水通量");
			
			highChartsParam6.setName("浓水通量");
			highChartsParam6.setY(Double.parseDouble(zcEvaluateEntity.getNstl()));
			highChartsParam6.setDrilldown("浓水通量");
			
			array[0] = highChartsParam1;
			array[1] = highChartsParam2;
			array[2] = highChartsParam3;
			array[3] = highChartsParam4;
			array[4] = highChartsParam5;
			array[5] = highChartsParam6;
			
			JSONArray jsonArray = JSONArray.fromObject(array);
			jsonObject.put("name", zcEvaluateEntity.getFacilityNumber());
	        jsonObject.put("colorByPoint", true);
	        jsonObject.put("data", jsonArray);
			ResponseUtil.write(response, jsonObject);
		} else {
			ResponseUtil.write(response, "");
		}
	}
}
